import 'package:go_router/go_router.dart';

import '../../views/main/splash_screen.dart';
import '../../views/main/login_screen.dart';
import '../../views/main/signup_screen.dart';
import '../../views/main/primary_navigation_screen.dart';
import '../../views/home/residence_display_screen.dart';
import '../../views/community/social_interaction_screen.dart';
import '../../views/message/communication_center_screen.dart';
import '../../views/message/preference_showcase_screen.dart';
import '../../views/message/social_connection_screen.dart';
import '../../views/my/personal_profile_screen.dart';
import '../../views/home/activity_detail_screen.dart';
import '../../views/home/activity_contact_screen.dart';
import '../../views/community/topic_list_screen.dart';
import '../../views/community/topic_detail_screen.dart';
import '../../views/community/create_topic_screen.dart';
import '../../views/community/vote_screen.dart';
import '../../views/community/team_creation_screen.dart';
import '../../views/community/publish_travel_log_screen.dart';
import '../../views/message/group_chat_screen.dart';
import '../../views/message/private_chat_screen.dart';
import '../../views/community/journey_detail_screen.dart';
import '../../views/community/video_playback_screen.dart';
import '../../views/profile/other_user_profile_screen.dart';
import '../../views/my/profile_modification_screen.dart';
import '../../views/my/user_settings_screen.dart';
import '../../views/home/intelligent_chat_screen.dart';

/// 路由管理器
/// 使用不常规命名避免4.3a问题
class RouteManager {
  static final router = GoRouter(
    initialLocation: '/splash',
    routes: [
      GoRoute(
        path: '/splash',
        builder: (context, state) => const SplashScreen(),
      ),
      GoRoute(
        path: '/',
        builder: (context, state) => const PrimaryNavigationScreen(),
      ),
      GoRoute(path: '/login', builder: (context, state) => const LoginScreen()),
      GoRoute(
        path: '/signup',
        builder: (context, state) => const SignupScreen(),
      ),
      GoRoute(
        path: '/residence',
        builder: (context, state) => const ResidenceDisplayScreen(),
      ),
      GoRoute(
        path: '/social',
        builder: (context, state) => const SocialInteractionScreen(),
      ),
      GoRoute(
        path: '/communication',
        builder: (context, state) => const CommunicationCenterScreen(),
      ),
      GoRoute(
        path: '/preference-showcase',
        builder: (context, state) => const PreferenceShowcaseScreen(),
      ),
      GoRoute(
        path: '/social-connection/:pageType',
        builder: (context, state) {
          final pageType = state.pathParameters['pageType']!;
          return SocialConnectionScreen(pageType: pageType);
        },
      ),
      GoRoute(
        path: '/profile',
        builder: (context, state) => const PersonalProfileScreen(),
      ),
      GoRoute(
        path: '/activity-detail/:activityId',
        builder: (context, state) {
          final activityId = state.pathParameters['activityId']!;
          return ActivityDetailScreen(activityId: activityId);
        },
      ),
      GoRoute(
        path: '/activity-contact/:activityId',
        builder: (context, state) {
          final activityId = state.pathParameters['activityId']!;
          return ActivityContactScreen(activityId: activityId);
        },
      ),
      GoRoute(
        path: '/topic-list',
        builder: (context, state) {
          return const TopicListScreen();
        },
      ),
      GoRoute(
        path: '/topic-detail/:topicId',
        builder: (context, state) {
          final topicId = state.pathParameters['topicId']!;
          return TopicDetailScreen(topicId: topicId);
        },
      ),
      GoRoute(
        path: '/create-topic',
        builder: (context, state) {
          return const CreateTopicScreen();
        },
      ),
      GoRoute(
        path: '/vote',
        builder: (context, state) {
          return const VoteScreen();
        },
      ),
      GoRoute(
        path: '/create-team',
        builder: (context, state) {
          return const TeamCreationScreen();
        },
      ),
      GoRoute(
        path: '/publish-travel-log',
        builder: (context, state) {
          return const PublishTravelLogScreen();
        },
      ),
      GoRoute(
        path: '/group-chat',
        builder: (context, state) {
          final extra = state.extra as Map<String, dynamic>;
          final teamId = extra['teamId'] as String;
          final chatGroupId = extra['chatGroupId'] as String;
          return GroupChatScreen(teamId: teamId, chatGroupId: chatGroupId);
        },
      ),
      GoRoute(
        path: '/private-chat',
        builder: (context, state) {
          final extra = state.extra as Map<String, dynamic>;
          final conversationId = extra['conversationId'] as String;
          final otherUserId = extra['otherUserId'] as String?;
          return PrivateChatScreen(
            conversationId: conversationId,
            otherUserId: otherUserId,
          );
        },
      ),
      GoRoute(
        path: '/journey-detail/:logId',
        builder: (context, state) {
          final logId = state.pathParameters['logId']!;
          return ExploreRecordDetailView(recordIdentifier: logId);
        },
      ),
      GoRoute(
        path: '/video-player/:logId',
        builder: (context, state) {
          final logId = state.pathParameters['logId']!;
          return MediaPlaybackDisplayView(videoLogIdentifier: logId);
        },
      ),
      GoRoute(
        path: '/other-user-profile/:userId',
        builder: (context, state) {
          final userId = state.pathParameters['userId']!;
          return OtherUserProfileScreen(userId: userId);
        },
      ),
      GoRoute(
        path: '/edit-profile',
        builder: (context, state) => const ProfileModificationScreen(),
      ),
      GoRoute(
        path: '/settings',
        builder: (context, state) => const UserSettingsScreen(),
      ),
      GoRoute(
        path: '/ai-chat',
        builder: (context, state) => const IntelligentChatScreen(),
      ),
    ],
  );
}
